{% extends 'ShopAdminBundle::my_form_add.html.twig'%}
{% set _module,_current='后台用户','添加权限' %}

{% block form_groups %}
    {% include 'ShopAdminBundle:AdminRole:form.html.twig' %}
{% endblock %}

{% block plugin_js %}
<script>
    (function(){
        var btn_checkall = $('#btn-check-all'),
                btn_uncheck = $('#btn-check-none');

        var priv_btns = $('div.priv-item input[type=checkbox]');
        var count_btn = priv_btns.length;

        btn_checkall.on('click', function(){
            if($(this).filter(':checked').length){
                $(priv_btns).each(function(i){
                    if(!$(this).filter(':checked').length){
                        $(this).trigger('click');
                    }
                });
            }
        });
        btn_uncheck.on('click', function(){
            if($(this).filter(':checked').length){
                $(priv_btns).each(function(i){
                    $(this).trigger('click');
                });
            }
            if(priv_btns.filter('checked').length != count_btn){
                if(btn_checkall.filter(':checked').length){
                    btn_checkall.trigger('click');
                }
            }
        });


        var priv_val=$('#priv-val').val().split(',');
        $(priv_btns).each(function(dx){
           if(priv_val.indexOf($(this).val()) !== -1){
               $(this).attr('checked',true);
           }
        });

    })();



</script>

{% endblock %}

